#ifndef _APPS_BWM_CSHUFFLERENDERER_H_
#define _APPS_BWM_CSHUFFLERENDERER_H_

#include "cdesktoprenderer.h"
#include "cclientdata.h"
#include <buola/gui/x11/cglx.h>

namespace buola { namespace bwm {

///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
////////////////// CShuffleRenderer //////////////////////
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////

class CShuffleRenderer : public CDesktopRenderer
{
    struct SSlot
    {
        double mDepth;
        mat::CVec3d mTranslate1;
        double mRotate;
        mat::CVec3d mTranslate2;
        double mAdjustment;
    };
    
    struct SClient
    {
        CManagedClient *mClient;
        double mScale;
        mat::CVec3d mOrigin;

        double mSlotStart;
        double mSlotCurrent;

        double mDepthPos;
        mat::CVec3d mTranslate1Pos;
        double mRotatePos;
        mat::CVec3d mTranslate2Pos;
    };

    class SClientData
    {
    public:
        bool mCirculable;
    };

    struct ADepthSort
    {
    public:
        bool operator()(SClient *p1,SClient *p2)
        {
            return (p1->mDepthPos<p2->mDepthPos);
        }
    };
    
///////////////////////////////
/////////// methods ///////////
///////////////////////////////

public:
//////////////
// creation
//
    CShuffleRenderer();
    ~CShuffleRenderer();

public:
    virtual void Enable();
    virtual void Disable();
    
//painting
    void Forward();
    void Backward();
    void GoIn();
    void GoOut();
    
    CManagedClient *GetCurrentClient();

protected:
/////////////////
// perspective
//

/////////////////////
// composite actions
//
public:
    virtual void Render(int pDesktop,ERenderMode pMode);
    virtual void OnLoop();

////////////////////////////
/////////// data ///////////
////////////////////////////
    USignal<void()> sOutFinished;

///////////////////////
// event and clients
//
protected:
    std::vector<SClient> mClients;
    std::vector<SSlot> mSlots;

    CSize_d mMaxSize;

    int mCurrent;

    double mInStep;
    double mShuffleStep;

    bool mFirst;
    bool mGoingOut;

    CClientData<SClientData> mClientData;
};

/*namespace bwm*/ } /*namespace buola*/ }

#endif
